#!/bin/bash

arg=$1

app_name='spark'
app_home='/opt/app/spark'
filter_str='echo $(jps|egrep "Master|Worker")'
function print()
{
        echo " │"
        echo " ├$app_name $1 节点"
        echo " └───────────────"
}
function start()
{
	echo "$app_name集群启动中..."
	ssh bigdata3 $app_home'/sbin/start-all.sh'
	print 3
	sleep 1
}
function stop()
{
	echo "$app_name集群停止中..."
	ssh bigdata3 $app_home'/sbin/stop-all.sh'
	print 3
	sleep 1
}
function status()
{
	echo "$app_name集群各个节点运行状态..."
	ssh bigdata1 $filter_str
	print 1
	ssh bigdata2 $filter_str
	print 2
	ssh bigdata3 $filter_str
	print 3
	
}
arg=$1
if [ "$arg" = "" ];then
	echo "请传入[start|stop|restart|status]参数,不传默认为[status]"
	arg="status"
	
fi
if [ "$arg" = "" ];then
        echo "请传参数start|stop|status|restart"
        exit 1
fi
if [ "$arg" = "start" ];then
        start
        echo "启动success"
		status
elif [ "$arg" = "stop" ];then
        stop
        echo "停止success"
		status
elif [ "$arg" = "status" ];then
	status
elif [ "$arg" = "restart" ];then
        stop
        start
		status
        echo "重启成功"
fi




